const validate = {
    name: (rule, value, callback) => {
        if (value === "" || value.replace(/(^\s*)|(\s*$)/g, "") === "" || (/^\s+$/gi).test(value)) {
            callback(new Error("不能为空,请正确填写"));
        } else {
            callback();
        }
    },
    enOnly: (rule, value, callback) => {
        if (value === "" || value.replace(/(^\s*)|(\s*$)/g, "") === "" || (/^\s+$/gi).test(value)) {
            callback(new Error("不能为空,请正确填写"));
        } else {
            if (/^[A-Za-z]+$/.test(value)) {
                callback();
            } else {
                callback(new Error("只允许填写英文"));
            }
        }
    },
    password: (rule, value, callback) => {
        if (value === '') {
            callback(new Error('密码不能为空'));
            return
        }
        if (value.length < 6) {
            callback(new Error('请输入至少6位数密码'));
            return
        }
        callback();
    },
    id:(rule, value, callback)=>{
        if (value === "" || value.replace(/(^\s*)|(\s*$)/g, "") === "" || (/^\s+$/gi).test(value)) {
            callback(new Error("不能为空,请正确填写！"));
        } else {
            if (/^[0-9a-zA-Z]+$/.test(value)) {
                callback();
            } else {
                callback(new Error("请填写英文或者数字！"));
            }
        }
    },
    can_empty_password: (rule, value, callback) => {
        if (value && value.length < 6) {
            callback(new Error('请输入至少6位数密码'));
            return
        }
        callback();
    },
    tel: (rule, value, callback) => {
        if (value && !(/^1[34578]\d{9}$/).test(value)) {
            callback(new Error('请输入正确的手机号'));
        } else {
            callback();
        }
    },
    cant_empty_tel: (rule, value, callback) => {
        if (value === '') {
            callback(new Error('手机号不能为空'));
            return
        }
        if (value && !(/^1[34578]\d{9}$/).test(value)) {
            callback(new Error('请输入正确的手机号'));
        } else {
            callback();
        }
    },
    email: (rule, value, callback) => {
        if (!(/^(\w)+(\.\w+)*@(\w)+((\.\w{2,3}){1,3})$/).test(value)) {
            callback(new Error('请输入正确的邮箱'));
        } else {
            callback();

        }
    },
    url: (rule, value, callback) => {
        if (value === "" || value.replace(/(^\s*)|(\s*$)/g, "") === "" || (/^\s+$/gi).test(value)) {
            callback(new Error("不能为空,请正确填写"));
            return
        }
        if (value.indexOf('http://') == -1 && value.indexOf('https://') == -1 && value.indexOf('http%3A%2F%2F') == -1 && value.indexOf('https%3A%2F%2F') == -1) {
            callback(new Error("请输入正确地址"));
            return
        }
        callback();
    },
    can_empty_url: (rule, value, callback) => {
        if (value && value.indexOf('http://') == -1 && value.indexOf('https://') == -1 && value.indexOf('http%3A%2F%2F') == -1 && value.indexOf('https%3A%2F%2F') == -1) {
            callback(new Error("请输入正确地址"));
            return
        }
        callback();
    },
    versioncode: (rule, value, callback) => {
        if (!value) {
            callback(new Error("不能为空"));
            return
        }
        if(!(/^\+?[1-9][0-9]*$/).test(Number(value))){
            callback(new Error("请输入小于10位正整数"));
            return
        }
        if(value.length > 10){
            callback(new Error("请输入小于10位正整数"));
            return
        }
        callback();
    }
}
export default validate;
